﻿using System;
using System.Data.SqlClient;
using System.Data;
using prjKQXS_DLL;

namespace prjKQXS_Report
{
    public partial class DSDaiLyCap1 : DevExpress.XtraReports.UI.XtraReport
    {
        Report_DAL report_dal = new Report_DAL();

        public DSDaiLyCap1(DateTime FromDate, DateTime ToDate, bool DaRutTC=true)
        {
            InitializeComponent();

            dsReports1 = report_dal.reportDungChung(dsReports1);

            try
            {
                SqlConnection conn = new SqlConnection(BienTc.connString);
                if (conn.State == ConnectionState.Closed)
                {
                    conn.Open();
                }

                //string DieuKien_DaRutTC="";
                //if (!DaRutTC) DieuKien_DaRutTC = " and (Thanh_Ly=1 and isDaRut=1) ";
                 string   SQL = "SELECT DMCANBO.Ma_DT, DMCANBO.Ten_DT, LAIXUAT_CB.SoPhieuThu AS So_CT, DMCANBO.Noi_O, " +
                        "Tien AS Goc, NgayBD AS Ngay_TinhLai, NgayRutTC AS Ngay_Rut " +
                        "FROM DMCANBO INNER JOIN LAIXUAT_CB ON DMCANBO.Ma_DT = LAIXUAT_CB.Ma_CB " +
                        "WHERE DMCANBO.Ma_DMChucVu = N'ĐLC1' and " +
                        "(CAST(CONVERT(nvarchar, LAIXUAT_CB.NgayBD, 112) AS int) >= @BeginDate) " +
                        "and (CAST(CONVERT(nvarchar, LAIXUAT_CB.NgayRutTC, 112) AS int) <= @EndDate) " + //DieuKien_DaRutTC +
                        "ORDER BY DMCANBO.Ten_DT";
                   
                    //Chuyển ngày tháng thành dạng số (dùng cho việc so sánh ngày tháng trong lệnh SQL ở trên)
                    int begin = Convert.ToInt32(FromDate.ToString("yyyyMMdd"));
                    int end = Convert.ToInt32(ToDate.ToString("yyyyMMdd"));

                    SqlDataAdapter da = new SqlDataAdapter(SQL, conn);
                    da.SelectCommand.Parameters.Clear();
                    da.SelectCommand.Parameters.AddWithValue("@BeginDate", begin);
                    da.SelectCommand.Parameters.AddWithValue("@EndDate", end);

                da.Fill(dsReports1.rptDSDaiLyTheChapCap1);
            }
            catch (Exception e)
            {
                throw;
            }
        }

        int stt = 0;
        private void Detail_BeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e)
        {
            stt++;
            lblSTt.Text = stt.ToString();
        }
    }
}
